<template>
	<div class="add-jq-dialog">
		
		<appdialog 
			ref="dialog"
      title="修改部门"
			:visible="false" 
			width="25%"
			@confirm="confirmAdd"
			@cancle="cancleAdd"
			>
      <el-form label-width="100px"  :model="ruleForm" ref="ruleForm"  :rules="rules" >
        <!-- <el-alert title="消息提示的文案" type="info"></el-alert> -->
        <el-form-item label="部门名称：" prop="deptName">
           <el-input v-model="ruleForm.deptName"></el-input>
        </el-form-item><br>
      </el-form>
		</appdialog>
	</div>
</template>

<script>
import {saveDept} from '@/service/swagger/DeptController.js'
import appdialog from "@/view/components/dialog/dialog";
import {updateDept} from '@/service/swagger/DeptController.js'
export default {
	name: "addjs",
	components: {
    appdialog,
	},
	data() {
		return {
			ruleForm:{
        deptName:'',
        deptId:'',
      },
      rules:{
        deptName:[
         	{ required: true, message: '请输入部门名称', trigger: 'change' },
        ]
      }
		}
	},
	mounted() {

	},
	methods: {
		open(row) {
      if(row){
        console.log(row)
        this.ruleForm.deptId = row.id
        this.ruleForm.disabled = row.disabled
        this.ruleForm.deptName = row.text
      }
			this.$refs.dialog.open();
		},
		confirmAdd() {
      this.$refs['ruleForm'].validate((valid) => {
				if (valid) {
          this.submit()
				} else {
					setTimeout(() => {
						this.open();
					}, 50)
					return false;
				}
			})
    },
    submit(){
      updateDept(this.ruleForm).then(ret=>{
        if(ret&&ret.code == 0){
          this.$emit('handleSuccess')
          this.$message({type: 'success',message: '操作成功!'})
        }else{
          this.$message({type: 'error',message: '操作失败!'})
        }
      })
    },
		cancleAdd() {
      this.ruleForm = {
        deptName:'',
        deptId:'',
      }
		},
	}
}
</script>

<style scoped lang="scss">
@import "../../../../styles/variables.scss";
</style>